package com.bluexmicro.example.page.menu

import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.IconButton
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.rememberNavController
import com.bluexmicro.example.R
import com.bluexmicro.example.route.*
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MenuPage() {
    val state = rememberScaffoldState()
    val scope = rememberCoroutineScope()
    val controller = rememberNavController()
    Scaffold(
        scaffoldState = state,
        topBar = {
            TopAppBar(
                title = { Text("BX OTA", color = MaterialTheme.colorScheme.onPrimary) },
                backgroundColor = MaterialTheme.colorScheme.primary,
                navigationIcon = {
                    IconButton(onClick = {
                        scope.launch {
                            state.drawerState.apply {
                                if (isOpen) close() else open()
                            }
                        }
                    }) {
                        Icon(
                            painter = painterResource(id = R.drawable.ic_baseline_menu_24),
                            null,
                            tint = MaterialTheme.colorScheme.onPrimary,
                            modifier = Modifier.size(24.dp)
                        )
                    }
                }
            )
        },
        drawerContent = {
            Button(onClick = {
                controller.navigate(SingleManual.Guide.root)
                scope.launch {
                    state.drawerState.close()
                }
            }) {
                Text("1")
            }
            Button(onClick = {
                controller.navigate(SingleAutomatic.Guide.root)
                scope.launch {
                    state.drawerState.close()
                }
            }) {
                Text("2")
            }
            Button(onClick = {
                controller.navigate(FlowLoop.Guide.root)
                scope.launch {
                    state.drawerState.close()
                }
            }) {
                Text("3")
            }
        },
        drawerShape = RoundedCornerShape(0.dp),
    ) {
       TestPage("ad"){

       }
    }
}

